<?php 
  session_start();
 function getClientInformation($sample_key, $database, $host, $login, $loginPassword){
	$con = mysql_connect($host,$login,$loginPassword) or die('Could not connect: ' . mysql_error());
	mysql_select_db($database) or die(mysql_error());
	
	$result = mysql_query("SELECT * FROM sample_details  WHERE sample_key = '$sample_key'")or die(mysql_error());
	$row = mysql_fetch_array($result);
	
	mysql_close($con);
	
	//if return nothing
	
	return $row;
 }
 
	function getCaslMinMax($sample_key, $database, $host, $login, $loginPassword){
		$con = mysql_connect($host,$login,$loginPassword) or die('Could not connect: ' . mysql_error());
		mysql_select_db($database) or die(mysql_error());
		
		$query="SELECT DISTINCT casl_no_year, MAX(casl_no_sample) AS maximum, 
			MIN(casl_no_sample) AS minimum FROM sample_entry  WHERE sample_key = '$sample_key'";
		$result = mysql_query($query)or die(mysql_error());
		$row = mysql_fetch_array($result);
		
		mysql_close($con);
		return $row;
	}
 
	function getSamples($sample_key, $database, $host, $login, $loginPassword){
		$returnValue = array();
		$con = mysql_connect($host,$login,$loginPassword) or die('Could not connect: ' . mysql_error());
		mysql_select_db($database) or die(mysql_error());
		
		$query="SELECT analysis_required, cost AS cost, COUNT(analysis_required) AS count, SUM(cost) AS total ,casl_no_year, casl_no_sample FROM sample_entry WHERE sample_key = $sample_key GROUP BY analysis_required";
		$result = mysql_query($query)or die(mysql_error());
		
		while ($row = mysql_fetch_array($result)){
			array_push($returnValue, $row);
		}
		mysql_close($con);
		return $returnValue;
	}
	
	function getAllSamples($sample_key, $database, $host, $login, $loginPassword){
		$returnValue = array();
		$con = mysql_connect($host,$login,$loginPassword) or die('Could not connect: ' . mysql_error());
		mysql_select_db($database) or die(mysql_error());
		
		$query="SELECT * FROM sample_entry WHERE sample_key = $sample_key";
		$result = mysql_query($query)or die(mysql_error());
		
		while ($row = mysql_fetch_array($result)){
			array_push($returnValue, $row);
		}
		mysql_close($con);
		return $returnValue;
	}
	
	function ClientExists($sample_key,$database,$host,$login,$loginPassword){
		$con = mysql_connect($host,$login,$loginPassword) or die('Could not connect: ' . mysql_error());
		mysql_select_db($database) or die(mysql_error());
	
		$result = mysql_query("SELECT COUNT(*) AS count FROM sample_details  WHERE sample_key = '$sample_key'")or die(mysql_error());
		$row = mysql_fetch_array($result);
		
		mysql_close($con);
	
		//if return nothing
		if($row["count"] > 0){
			return true;
		}
		else{
			return false;
		}	
	}
	
	function getStatus($sample_key, $database, $host, $login, $loginPassword){
		$con = mysql_connect($host,$login,$loginPassword) or die('Could not connect: ' . mysql_error());
		mysql_select_db($database) or die(mysql_error());
		
		$query="SELECT status FROM sample_entry  WHERE sample_key = '$sample_key'";
		$result = mysql_query($query)or die(mysql_error());
		$row = mysql_fetch_array($result);
		
		mysql_close($con);
		return $row;
	}
	
?>